home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Arashi 1.1.1 / source code / Game Source / jam src / new.GameLoop.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-23  |  7.1 KB  |  339 lines  |  [TEXT/KAHL]

  1. /*/
  2.      Project Arashi: new.GameLoop.c
  3.      Major release: Version 1.1d2, 9/5/95
  4.  
  5.      Last modification: Tuesday, March 23, 1993, 20:51
  6.      Created: Sunday, March 14, 1993, 22:00
  7.  
  8.      Copyright © 1993, Juri Munkki
  9. /*/
  10.  
  11. #include "VA.h"
  12. #include "STORM.h"
  13. #include "Shuddup.h"
  14. #include "PlayOptions.h"
  15. #include "GamePause.h"
  16. #include "HighScoresToBeat.h"        /* mz */
  17. #include <GestaltEqu.h>
  18. #include <OSUtils.h>
  19. #include <Types.h>
  20. #include "heroflags.h"
  21.  
  22. #define DEBUGGING_ROUTINES
  23.  
  24. static     int    highestLastLevel=9;            /* (mz) */
  25.         int    FinalDeathMode=1;
  26.         
  27. extern    Player    Hero;
  28. extern    int        OldSound;                /*    Flag for Sound Kit        */
  29.  
  30.  
  31. Initials    *HiScoresToBeat;
  32. int         ScoretoBeatIndex;
  33.  
  34. EventRecord        Event;
  35. WindowPtr        BackdropWind;
  36.  
  37.  
  38. void    GameLoop(Options)
  39. int        Options;
  40. {
  41.     int            i;
  42.     long int    levelStBonus=0;
  43.     long int    levelBonus=0;
  44.     int            levelComplete=0;
  45.     Handle        ScoreHand;
  46.     int            DoomsdayDeath = 0;
  47.     
  48.     /* read scores from resources  for top right corner */
  49.     if (PlayOptions->restart == 0)
  50.         ScoreHand=GetResource('SCOR',128);
  51.     else 
  52.         ScoreHand=GetResource('SCOR',129);
  53.     HLock(ScoreHand);
  54.     HiScoresToBeat = (Initials *)*ScoreHand;
  55.     ScoretoBeatIndex = 50;        /* start at the bottom */
  56.     
  57.     VAEraseBuffer();
  58.  
  59.     /*    Flush out some events and let MultiFinder update windows.    */
  60.     for(i=0;i<10;i++)
  61.         GameEvent();
  62.  
  63.     ZeroScore();
  64.     
  65.     if(Options == NormalPlay)
  66.     {    StartNormalPlay();
  67.     }
  68.     else
  69.     {    Hero.lives = 0;
  70.         LoadPlayRecord();
  71.         if(Options == RecordPlay)
  72.         {    StartPlayRecord();
  73.         }
  74.         else
  75.         if(Options == PlaybackPlay)
  76.         {    StartPlayback();
  77.         }
  78.     }
  79.  
  80.     DisplayLives();
  81.  
  82.     do
  83.     {    VACatchUp();
  84.  
  85.         DisplayScore();
  86.  
  87.         if(Hero.state != HeroDead)
  88.         {    AddLife();
  89.             if (levelComplete == 1)
  90.             {
  91.                 /* check to see if starting level not finished (mz)                 */
  92.                 if (!(Hero.Flags & FirstLevelMask))
  93.                 {    /* set start bonus granted and show zap */
  94.                     Hero.Flags |= (ShowSuperZapMsgMask + FirstLevelMask ); 
  95.                     IncreaseScore(levelStBonus); /* give starting bonus                */
  96.                 } 
  97.                 if(!(Hero.Flags & SavedgameFirstLVLMask))
  98.                 {
  99.                     Hero.Flags |= ShowSuperZapMsgMask;
  100.                     Hero.Flags |= ShowSuperZapMsgMask;
  101.                 }
  102.                 IncreaseScore(levelBonus);
  103.                 DisplayScore();            
  104.             }
  105.             levelComplete = 0;
  106.             levelBonus = 0;
  107.             levelStBonus = 0;
  108.             STLoadLevel(); 
  109.             CreateFit();
  110.         }
  111.         else if(DoomsdayDeath)
  112.         {
  113.             int    numzaps=ThisLevel.plSuperZaps;
  114.             
  115.             ThisLevel.lvType = 3;                /* set flag for Dommsday death         */
  116.             STLoadLevel(); 
  117.             ThisLevel.plSuperZaps = numzaps;    /* Keep old # of zaps                 */
  118.             Hero.Flags &= (FLAGSMASK - 0x0020);    /* unset re-zap msg                    */
  119.             CreateFit();
  120.             Hero.Flags &= 0x0020;                /* set show re-zap msg                 */
  121.             DoomsdayDeath = 0;
  122.         }
  123.         else
  124.         {    VA.color=0;
  125.             RedrawField();
  126.         }
  127.         
  128.         RemoveLife();
  129.         STInitialize();
  130.     
  131.         do
  132.         {    if(Options != PlaybackPlay)
  133.             {    GameEvent();
  134.                 switch(Event.what)
  135.                 {    case keyDown:
  136.                     case autoKey:
  137.                         switch(Event.message & 0xFF)
  138.                         {    case 'q':
  139.                             case 'Q':
  140.                             case 27:
  141.                             case 13:    Hero.state=HeroDead;
  142.                                         Hero.lives=0;                
  143.                                         FinalDeathMode=0;
  144.                                         break;
  145.                             case ' ':    /* Handled in player routine    */
  146.                                                                     break;
  147.                             case 'p':
  148.                             case 'P':    GamePause(GameRunning);     
  149.                                         break;
  150.     #ifdef DEBUGGING_ROUTINES
  151.                             case 26:    DumpThisLevel();            break;
  152.                             case '1':    AddLife();                    break;
  153.                             case '2':    RemoveLife();                break;
  154.  
  155.                             case 'z':    CreateNewFlipper();            break;
  156.                             case 'x':    CreateNewTanker(0);            break;
  157.                             case 's':    CreateNewTanker(1);            break;
  158.                             case 'd':    CreateNewTanker(2);            break;
  159.                             case 'c':    CreateNewPulsar();            break;
  160.                             case 'v':    CreateNewBall();            break;
  161.  
  162.                         /*    case '@':    Hero.state=HeroFlying;
  163.                                         DemoMode();                    break;
  164.                             case 'k':    TestZoomRect();                break;
  165.                             case 'l':    DoLevelSelect();            break; */
  166.                             default:    Hero.state=HeroFlying;        break;
  167.      #endif
  168.                         }
  169.                         break;
  170.                 }
  171.             }
  172.             else    /*    Playback active.    */
  173.             {    if(GamePeekEvent())
  174.                 {    Hero.lives = 0;
  175.                     Hero.state = HeroDead;
  176.                 }
  177.                 Event.what = 0;
  178.             }
  179.             if(ThisLevel.activeCount<ThisLevel.boredomCount)
  180.                 ThisLevel.probIncrease=ThisLevel.boredProb;
  181.             else
  182.                 ThisLevel.probIncrease=0;
  183.             ThisLevel.activeCount=0;
  184.  
  185.             STUpdate();
  186.  
  187.             VA.segmscale=5;
  188.  
  189.             VA.color = BG2; 
  190.             if (!(PlayOptions->restart == 0))    /* only show count if Practice mode */
  191.             {
  192.                 if (ThisLevel.lvColor == 5)        /* check for invis lvl where BG2 is */
  193.                     VA.color=BG1;                /* also invis. (mz)                 */
  194.                 VADrawPadNumber(ThisLevel.totalCount,VA.frame.right-10,60,3);
  195.                 VADrawPadNumber(ThisLevel.edgeCount,VA.frame.right-10,80,3);
  196.                 VA.color = BG2;
  197.             }
  198.             VAStep();
  199.             
  200.             if(Hero.state == HeroPlaying)
  201.             {    if(ThisLevel.edgeCount==ThisLevel.totalCount)
  202.                 {    Hero.endtimer--;
  203.                     if(Hero.endtimer<=0)
  204.                     {    Hero.state=HeroFlying;
  205.                         Hero.flydepth=0;
  206.                         levelComplete=1;
  207.                         levelStBonus=ThisLevel.lvStBonus;
  208.                         levelBonus=ThisLevel.lvBonus;
  209.                     }
  210.                 }
  211.             }
  212.         
  213.         } while(Hero.state != HeroDead && Hero.state != HeroFlying);
  214.  
  215.         if(Hero.state == HeroFlying)
  216.             STFlyThruLoop(Options);
  217.             
  218.         if(ThisLevel.lvType == 4 && Hero.lives>0) /* player has died in Doomsday level */
  219.         {    DoomsdayDeath = 1;
  220.             VA.color=-1;    /*    Black                    */
  221.             RedrawField();
  222.             RedrawSpikes();
  223.         }
  224.     
  225.     } while(Hero.lives>0 || Hero.state != HeroDead);
  226.     
  227.     if (FinalDeathMode && Options == NormalPlay)
  228.         STFlyOutLoop();            /* test */
  229.     
  230.     FinalDeathMode = 1;
  231.     
  232.     highestLastLevel = ThisLevel.lvNumber - 1;    /* at end of game save highest level */
  233.     
  234.     if(Options != NormalPlay)
  235.     {    if(Options == RecordPlay)
  236.         {    WriteRecordedPlay();
  237.         }
  238.         UnloadPlayRecord();
  239.     }    
  240. }
  241.  
  242.  
  243. int        StormStart()
  244. {
  245.     int                zero=0;
  246.     int                i;
  247.     Handle            TheDevice;
  248.     long            myFeature;
  249.     
  250.     DoInits();
  251.     
  252.     /* Now do check for Color Quickdraw. Any version above simple 8 bit will do. */
  253.     if(Gestalt(gestaltQuickdrawVersion, &myFeature))
  254.     {
  255.         Alert(203,0);
  256.         ExitToShell();
  257.     }
  258.     if (myFeature < gestalt8BitQD)
  259.     {
  260.         Alert(201,0);
  261.         ExitToShell();
  262.     }
  263.     
  264.     
  265.     randSeed= Ticks;
  266.     VARandSeed= Ticks;
  267.  
  268.     TheDevice=ScreenSelect();
  269.     if(TheDevice==0)    return -1;
  270.     
  271.     if(PlayOptions->sys607Sound)
  272.     {    OldSound=0;
  273.     }
  274.     else
  275.     {    OldSound=1;
  276.     }
  277.     if(!PlayOptions->soundOff)
  278.         InitSoundKit();
  279.         
  280.     if(PlayOptions->blankUnused)
  281.         BackdropWind = NewWindow(0,&((*GrayRgn)->rgnBBox),&zero,-1,plainDBox,0,0,0);
  282.     else
  283.     {    Rect    SmallRect = { 0,0,10,10};
  284.         BackdropWind = NewWindow(0,&SmallRect,&zero,-1,plainDBox,0,0,0);
  285.     }    
  286.     VAInit(TheDevice);
  287.     if(PlayOptions->verticalGame)
  288.     {    i=VA.frame.bottom*4L/5;
  289.         if(VA.frame.right>i)
  290.             VA.frame.right=i;
  291.     }
  292.  
  293.     VAInitFractalLines();  /* only change I saw. copied to work file (mz) */
  294.     STAllocate();
  295.  
  296.     /*    Flush out some events and let MultiFinder update windows.    */
  297.     for(i=0;i<10;i++)    GameEvent();
  298.     
  299.     return 0;
  300. }
  301.  
  302. long    PlayGame(HighScore,Options)
  303. long    HighScore;
  304. int        Options;
  305. {
  306.     int        i;
  307.     
  308.     Hero.score = -1;
  309.     i=DoLevelSelect(&highestLastLevel);            /* transfer variable (mz)         */
  310.     if(!(Hero.Flags & SavedGameStartMask))
  311.         ThisLevel.lvType=0;                        /* reset if from random (mz)     */
  312.     else
  313.     {
  314.         Hero.Flags &= (FLAGSMASK - SavedgameFirstLVLMask);
  315.     }
  316.     if(i>=0)
  317.     {    VA.FrameSpeed=3;
  318.         ThisLevel.lvNext=i;
  319.         GameLoop(Options);
  320.     }
  321.     else
  322.         Hero.score = -1;    
  323.     return    Hero.score;
  324. }
  325.  
  326. void    PlayDemoGame()
  327. {
  328.     long    seeder;
  329.     
  330.     seeder = VARandSeed;
  331.     GameLoop(PlaybackPlay);
  332.     VARandSeed = seeder;
  333. }
  334.  
  335. void    RecordDemoGame()
  336. {
  337.     ThisLevel.lvNext = 3;
  338.     GameLoop(RecordPlay);
  339. }